module ApplicationHelper
  
  def user_authenticated
    get_current_user
    !@user.blank?
  end
  
  def get_current_user_name
    @user.name
  end
  
  def get_current_user_id
    @user.id
  end
  
  def get_current_user_email
    @user.email
  end
  
  def link_to_profile(id, size, imgStyle = "")
    link = "<a href=\"/profile/show/#{id}\">" + 
            "<img class=\"red-border\" style=\"#{imgStyle}\" src=\"/images/user/#{id}/#{size}.jpg\" alt=\"Profil-Bild\" />" +
           "</a>"
    return link
  end
  
  def link_to_bar(id, size)
    link = "<a href=\"/bars/show/#{id}\">" + 
            "<img class=\"red-border\" src=\"/images/bar/#{id}/#{size}.jpg\" alt=\"Bar-Bild\" />" +
           "</a>"
    return link
  end
  
  def get_newest_users
    User.find(:all, :order => "registration_date desc")
  end
  
  def tagged_form_for(name, *args, &block)
    options = args.last.is_a?(Hash) ? args.pop : {}
    options = options.merge(:builder => TaggedBuilder)
    args = (args << options)
    form_for(name, *args, &block)
  end
  
  def tagged_form(*args, &block)
    options = args.last.is_a?(Hash) ? args.pop : {}
    options = options.merge(:builder => TaggedBuilder)
    args = (args << options)
    form_tag(*args, &block)
  end
  
  private 
  
  def get_current_user
    if !session[:user_id].nil? and @user.nil?
      @user = User.find_by_id(session[:user_id])
    else
      @user = nil
    end
  end
end
